Skip to content

add Dockerfile and GitHub action for building image #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 8, 2025

Conversation

willnorris
Copy link
Member

@willnorris willnorris commented Jun 7, 2024

This largely mirrors the default Caddy image. (I generally use chainguard images to limit dependencies, but stuck with alpine, since that's what Caddy uses for it's main images)

The GitHub Action is duplicated from what we have for tailscale/golink. I don't really know a lot of best practices for Dockerfiles, so am really looking for any input. I have this using the simple.caddyfile as the default config, which is easy to override.

Updates #14

@willnorris willnorris requested a review from irbekrm June 7, 2024 05:25
@willnorris willnorris force-pushed the will/dockerfile branch 2 times, most recently from 5e15b1a to 6ce2c3e Compare June 7, 2024 05:46
@willnorris
Copy link
Member Author

wow, 16 minutes to build the image for two platforms :(

Copy link
Contributor

@irbekrm irbekrm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense in general, I've left two suggestions.

I think ko would be faster than Docker build, but it seems like it is not possible to expose ports using ko ko-build/ko#472

labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64

# Sign the Docker image
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

Dockerfile Outdated
Comment on lines 5 to 6
RUN go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest && \
xcaddy build v${CADDY_VERSION} --with github.com/tailscale/caddy-tailscale@main --output /usr/bin/caddy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
RUN go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest && \
xcaddy build v${CADDY_VERSION} --with github.com/tailscale/caddy-tailscale@main --output /usr/bin/caddy
RUN go run github.com/caddyserver/xcaddy/cmd/xcaddy@latest build v${CADDY_VERSION} \
--with github.com/tailscale/caddy-tailscale@main --output /usr/bin/caddy

maybe makes it a little faster?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I'm wondering if we can use the tailscale-caddy repo checkout available to this action rather than refer to github.com/tailscale/caddy-tailscale@main? The checkout should presumably bet the one corresponding to the push event

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be surprised if go run was actually any faster, but certainly doesn't hurt so let's give it a try.

And oops, totally forgot to instruct it to use the local source for building. I'll add that.

@willnorris
Copy link
Member Author

I think ko would be faster than Docker build, but it seems like it is not possible to expose ports using ko ko-build/ko#472

EXPOSE is really just to document what ports are exposed mapped, right? But it's not really necessary to be able to map ports?

It also looks like ko really wants a simple main package that it can build. That would mean bypassing xcaddy entirely for our builds and having our own simple cmd. Which is totally fine, that's actually what I do for my personal website. I'll actually do that first as a separate PR.

@willnorris willnorris marked this pull request as draft June 7, 2024 18:41
@irbekrm
Copy link
Contributor

irbekrm commented Jun 7, 2024

It also looks like ko really wants a simple main package that it can build. That would mean bypassing xcaddy entirely for our builds and having our own simple cmd.

We also have our own container builder that is a stripped down version of ko and that allows to include multiple binaries https://github.com/tailscale/mkctr. But I think we don't have an option to include static files with that

@irbekrm
Copy link
Contributor

irbekrm commented Jun 7, 2024

EXPOSE is really just to document what ports are exposed mapped, right? But it's not really necessary to be able to map ports?

That is my understanding, yes. Also, we don't expose ports for any of the other images we build (for example the k8s-operator that runs a server and listens on 443 and the tsrecorder)

@shyim
Copy link

shyim commented May 5, 2025

Hey,

Can I help u too get this merged? I have some ideas how to make the pipeline faster, if that is the blocking thing :)

@willnorris
Copy link
Member Author

Can I help u too get this merged? I have some ideas how to make the pipeline faster, if that is the blocking thing :)

heh, I think I honestly forgot this PR was out there! 😄 I think when I switched this back to a draft PR, it was because I was going to setup the separate main package, so then we could use ko to build? I'll try and find some time to work on that this week.

What ideas did you have about making the pipeline faster?

@shyim
Copy link

shyim commented May 5, 2025

just let go handle the cross compiling, see docker blog post :)
https://www.docker.com/blog/faster-multi-platform-builds-dockerfile-cross-compilation-guide/

did that last week here too :) muety/wakapi#781

This largely mirrors the default Caddy image.

Updates #14

Signed-off-by: Will Norris <will@tailscale.com>
@willnorris willnorris marked this pull request as ready for review May 8, 2025 17:52
@willnorris
Copy link
Member Author

okay, rebased onto main and am now using ./cmd/caddy rather than building with xcaddy. This simplifies the Dockerfile, and makes it easier to keep versions in sync, since it's just now using whatever caddy version is specified in go.mod.

I tried to build with ko, but I'm finding that it's juts too opinionated and limiting. It also uses the chainguard base image which dropped support for arm7 last year. I still want to be able to support previous generation raspberry pis, so am building on top of alpine instead. (We changed golink for similar reasons).

@willnorris willnorris merged commit 642f61f into main May 8, 2025
4 of 5 checks passed
@willnorris willnorris deleted the will/dockerfile branch May 8, 2025 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants